package com.zline.foodraise.util;

import android.content.Context;
import android.text.style.SuperscriptSpan;
import com.zline.foodraise.view.supertoast.SuperToast;
/*
 * Toast 统一管理工具类
 * */
public class TUtil {
	 private TUtil()  
	    {  
	        /* cannot be instantiated */  
	        throw new UnsupportedOperationException("cannot be instantiated");  
	    }  
	  
	    public static boolean isShow = true; 
	    private static SuperToast toast;
	  
	    /** 
	     * 短时间显示Toast 
	     *  
	     * @param context 
	     * @param message 
	     */  
	    public static void showShort(Context context, CharSequence message)  
	    {  
	        if (isShow){ 
	        	if(toast==null){
	        	toast=new SuperToast(context);
	        	toast.setDuration(SuperToast.Duration.SHORT);
	        	toast.setTextSize(SuperToast.TextSize.SMALL);
	        	toast.setText(message);
	        	}else{
	        		toast.setText(message);
	        	}
	        toast.show();
	        }  
	    }  
	  
	    /** 
	     * 短时间显示Toast 
	     *  
	     * @param context 
	     * @param messageId
	     */  
	    public static void showShort(Context context, int messageId)  
	    {  
	    	 if (isShow){ 
	    		 String message=context.getResources().getString(messageId);
		        	if(toast==null){
		        		toast=new SuperToast(context);
			        	toast.setDuration(SuperToast.Duration.SHORT);
			        	toast.setTextSize(SuperToast.TextSize.SMALL);
			        	toast.setText(message);	
		        	}else{
		        		toast.setText(message);
		        	}
		        toast.show();
		        }  
	    }  
	  
	    /** 
	     * 长时间显示Toast 
	     *  
	     * @param context 
	     * @param message 
	     */  
	    public static void showLong(Context context, CharSequence message)  
	    {  
	    	 if (isShow){ 
		        	if(toast==null){
		        		toast=new SuperToast(context);
			        	toast.setDuration(SuperToast.Duration.LONG);
			        	toast.setTextSize(SuperToast.TextSize.SMALL);
			        	toast.setText(message);
		        	}else{
		        		toast.setText(message);
		        	}
		        toast.show();
		        }   
	    }  
	  
	    /**
		 *
		 * @param context
		 * @param messageId
		 */
	    public static void showLong(Context context, int messageId)  
	    {  
	    	 if (isShow){ 
	    		 String message=context.getResources().getString(messageId);
		        	if(toast==null){
		        		toast=new SuperToast(context);
			        	toast.setDuration(SuperToast.Duration.LONG);
			        	toast.setTextSize(SuperToast.TextSize.SMALL);
			        	toast.setText(message);
		        	}else{
		        		toast.setText(message);
		        	}
		        toast.show();
		        }    
	    }  
	  
	    /** 
	     * 自定义显示Toast时间 
	     *  
	     * @param context 
	     * @param message 
	     * @param duration 
	     */  
	    public static void show(Context context, CharSequence message, int duration)  
	    {  
	        if (isShow) {
	        	if(toast==null){
	        		toast=new SuperToast(context);
		        	toast.setDuration(duration);
		        	toast.setTextSize(SuperToast.TextSize.SMALL);
		        	toast.setText(message);
	        	}else{
	        		toast.setText(message);
	        	}
	        	toast.show();
	        } 
	             
	    }  
	  
	    /** 
	     * 自定义显示Toast时间 
	     *  
	     * @param context 
	     * @param messageId
	     * @param duration 
	     */  
	    public static void show(Context context, int messageId, int duration)  
	    {  
	    	if (isShow) {
	    		 String message=context.getResources().getString(messageId);
	        	if(toast==null){
	        		toast=new SuperToast(context);
		        	toast.setDuration(duration);
		        	toast.setTextSize(SuperToast.TextSize.SMALL);
		        	toast.setText(message);
	        	}else{
	        		toast.setText(message);
	        	}
	        	toast.show();
	        }  
	    }  

}
